package com.google.code.resistorboy;

/**
 * Bean of resistance information.
 * @author leandro
 */
public class Resistance {
    private float value;      //nominal value
    private String exp;       // k or M
    private int tolerance;    // in %
    private int temperature;  // in PPM/C

    public static int UNKNOWN = -1;

    public Resistance() {
        this.exp = "";
        this.temperature = UNKNOWN;
    }

    public Resistance(float value, String exp, int tolerance,
            int temperature) {
        this.value = value;
        this.exp = exp;
        this.tolerance = tolerance;
        this.temperature = temperature;
    }

    public void setExp(String exp) {
        this.exp = exp;
    }

    public void setTemperature(int temperature) {
        this.temperature = temperature;
    }

    public void setTolerance(int tolerance) {
        this.tolerance = tolerance;
    }

    public void setValue(float value) {
        this.value = value;
    }

    public String getExp() {
        return exp;
    }

    public int getTemperature() {
        return temperature;
    }

    public int getTolerance() {
        return tolerance;
    }

    public float getValue() {
        return value;
    }

    public String toString() {
        String result = null;

        //to avoid ".0" after resistance value
        if (value == ((int)value)) {
            result = "Resistance: " + ((int)value) + exp + "ohms, +-"
                    + tolerance + "%";
        } else {
            result = "Resistance: " + value + exp + "ohms, +-"
                    + tolerance + "%";
        }

        if (temperature != UNKNOWN) {
            result += "Temperature tol.:" + temperature + " PPM/C";
        }

        return result;
    }

}
